cfile = app_sys("golem-config.yml")
conf = yaml::read_yaml(cfile, eval.expr = FALSE)

cache_size = conf$default$coco.cache_size
cache_dir = conf$default$coco.cache_dir
if (length(cache_size) != 1) {
  stop("cache size must set with a number in GB scale")
}
if (length(cache_dir) != 1) {
  stop("cache path must set with a directory")
}
if (grepl("\\(", cache_dir)) {
  cache_dir = eval(parse(text = cache_dir))
}

if (!is.null(cache_size)) {
  max_size = cache_size * 1024 ^ 3
} else {
  max_size = 1024 * 1024^2
  cache_size = 2 / 1024
}

mm = cachem::cache_disk(cache_dir, max_size)
message("Cache path: ", cache_dir)
message("Cache size: ", cache_size, " GB")

database = memoise::memoise(database, cache = mm)

cohorts = memoise::memoise(cohorts, cache = mm)
cohort_ls = memoise::memoise(cohort_ls, cache = mm)

datasets = memoise::memoise(datasets, cache = mm)
dataset_info = memoise::memoise(dataset_info, cache = mm)
dataset_load = memoise::memoise(dataset_load, cache = mm)
dataset_query_idx = memoise::memoise(dataset_query_idx, cache = mm)
